﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chowpoo.Sql;
using CourseSystem.Core.Entities;
using CourseSystem.Core.SqlServerDAL;

namespace CourseSystem.Core.BLL
{
    public class TeacherBLL : CommonBLL<TeacherInfo, TeacherDAL>
    {

        public static TeacherInfo Get(int id)
        {
            using (var dal = new TeacherDAL(Settings.ConnectionName))
            {
                var re = dal.SelectSingle(o => o.Id == id);
                return re;
            }
        }

        public static List<TeacherInfo> GetAllTeacher()
        {
            var re = GetAll();
            return re.Where(o => !o.IsAdmin).ToList();
        }

        public static bool Del(int id)
        {
            using (var dal = new TeacherDAL(Settings.ConnectionName))
            {
                return dal.Delete(o => o.Id == id) != null;
            }
        }


        public static bool IsExist(string account, int id = 0)
        {
            using (var dal = new TeacherDAL(Settings.ConnectionName))
            {
                return dal.SelectSingle(o => o.Id != id && o.Account == account) != null;
            }
        }

        public static TeacherInfo Login(string uid, string pass)
        {
            using (var dal = new TeacherDAL(Settings.ConnectionName))
            {
                return dal.SelectSingle(o => o.Account == uid && o.Pass == pass);
            }
        }


    }
}
